package com.gomokult.servlet.gamelib;

import com.gomokult.dao.impl.UserDAOImpl;
import com.gomokult.entity.Game;
import com.gomokult.service.impl.GamesLibraryServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Timestamp;

/**
 * 文件：DeleteCommentServlet.java
 * 作者：赵哲群
 * 完成度：已完成
 * 最后修改日期：2023-7-6
 */
@WebServlet("/servlet/SubmitGameDataServlet")
public class SubmitGameDataServlet extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        int userblack = Integer.parseInt(request.getParameter("userBlack"));
        int userwhite = Integer.parseInt(request.getParameter("userWhite"));
        String winner = request.getParameter("winner");
        String piecessequence = request.getParameter("piecesSequence");
        Timestamp date = new Timestamp(Long.parseLong(request.getParameter("date")));
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int blackDuration = Integer.parseInt(request.getParameter("blackDuration"));
        int whiteDuration = Integer.parseInt(request.getParameter("whiteDuration"));
        String blackcount = request.getParameter("blackCounting");
        String whitecount = request.getParameter("whiteCounting");

//            Timestamp date = (Timestamp) dateFormat.parse(date1);
        Game game = new Game(UserDAOImpl.getSingleton().selectUserbyID(userblack),UserDAOImpl.getSingleton().selectUserbyID(userwhite) ,winner,piecessequence,date,blackDuration,whiteDuration,blackcount,whitecount,0,0);
        out.print(GamesLibraryServiceImpl.getSingleton().submitGame(game));

    }
}
